package com.xomily.devops.service.impl;

import java.util.List;
import com.xomily.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xomily.devops.mapper.DevDiscMapper;
import com.xomily.devops.domain.DevDisc;
import com.xomily.devops.service.IDevDiscService;

/**
 * 磁盘运维日志Service业务层处理
 * 
 * @author xomily
 * @date 2021-11-29
 */
@Service
public class DevDiscServiceImpl implements IDevDiscService 
{
    @Autowired
    private DevDiscMapper devDiscMapper;

    /**
     * 查询磁盘运维日志
     * 
     * @param id 磁盘运维日志主键
     * @return 磁盘运维日志
     */
    @Override
    public DevDisc selectDevDiscById(Long id)
    {
        return devDiscMapper.selectDevDiscById(id);
    }

    /**
     * 查询磁盘运维日志列表
     * 
     * @param devDisc 磁盘运维日志
     * @return 磁盘运维日志
     */
    @Override
    public List<DevDisc> selectDevDiscList(DevDisc devDisc)
    {
        return devDiscMapper.selectDevDiscList(devDisc);
    }

    /**
     * 新增磁盘运维日志
     * 
     * @param devDisc 磁盘运维日志
     * @return 结果
     */
    @Override
    public int insertDevDisc(DevDisc devDisc)
    {
    	DevDisc discQuery = new DevDisc();
        discQuery.setIp(devDisc.getIp());
        discQuery.setName(devDisc.getName());
        DevDisc disc=devDiscMapper.selectDevDiscByIpName(discQuery);
        if (disc != null) {
            devDisc.setId(disc.getId());        	
            devDisc.setUpdateTime(DateUtils.getNowDate());
            return devDiscMapper.updateDevDiscByInfo(devDisc);
        } else {
            devDisc.setCreateTime(DateUtils.getNowDate());
            devDisc.setUpdateTime(DateUtils.getNowDate());
            return devDiscMapper.insertDevDisc(devDisc);        	
        }

    }

    /**
     * 修改磁盘运维日志
     * 
     * @param devDisc 磁盘运维日志
     * @return 结果
     */
    @Override
    public int updateDevDisc(DevDisc devDisc)
    {
        devDisc.setUpdateTime(DateUtils.getNowDate());
        return devDiscMapper.updateDevDisc(devDisc);
    }

    /**
     * 批量删除磁盘运维日志
     * 
     * @param ids 需要删除的磁盘运维日志主键
     * @return 结果
     */
    @Override
    public int deleteDevDiscByIds(Long[] ids)
    {
        return devDiscMapper.deleteDevDiscByIds(ids);
    }

    /**
     * 删除磁盘运维日志信息
     * 
     * @param id 磁盘运维日志主键
     * @return 结果
     */
    @Override
    public int deleteDevDiscById(Long id)
    {
        return devDiscMapper.deleteDevDiscById(id);
    }
}
